package com.alnex.mypat.listener;

import com.alnex.mypat.main.PatMain;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class MouseListener extends MouseAdapter {
    private Point origin = new Point();
    public  boolean voice = false;
    @Override
    public void mousePressed(MouseEvent e) {
        origin.x = e.getX();
        origin.y = e.getY();
        if(origin.x>145 && origin.x<165 && origin.y>210 && origin.y<255 ){
            //点击腿
            System.out.println("小脚被点击了");
            //脚被点击的时候让宠物跳舞
            PatMain.action=2;
            PatMain.startFrame = 1;
            PatMain.endFrame = 73;
            //
        }else {
            PatMain.action=1;
            PatMain.startFrame = 1;
            PatMain.endFrame = 8;
        }

        //鼠标事件
        if (e.getButton() == MouseEvent.BUTTON1) {
//                    JOptionPane.showMessageDialog(frame, "鼠标左键");
        } else if (e.getButton() == MouseEvent.BUTTON2) {
//                    JOptionPane.showMessageDialog(frame, "鼠标滚轮点击");
        } else if (e.getButton() == MouseEvent.BUTTON3) {
//                    JOptionPane.showMessageDialog(frame, "鼠标右键");
        }
    }

    /**
     * 鼠标移进标题栏时，设置鼠标图标为移动图标
     */
    public void mouseEntered(MouseEvent e) {
        PatMain.frame.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    }

    /**
     * 鼠标移出标题栏时，设置鼠标图标为默认指针
     */
    public void mouseExited(MouseEvent e) {
        PatMain.frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    }

    /**
     * 鼠标在标题栏拖拽时，设置窗口的坐标位置
     * 窗口新的坐标位置 = 移动前坐标位置+（鼠标指针当前坐标-鼠标按下时指针的位置）
     */
    public void mouseDragged(MouseEvent e) {
        Point p = PatMain.frame.getLocation();
        PatMain.frame.setLocation(
                p.x + (e.getX() - origin.x),
                p.y + (e.getY() - origin.y));
    }

    public void mouseMoved(MouseEvent e) {}

    public void mouseClicked(MouseEvent e) {

        if (e.getButton() == MouseEvent.BUTTON1
                && e.getClickCount() == 2) {
            System.out.println("鼠标双击");
            //双击让宠物处于等待状态


        }
    }
}
